package com.linwen.javase.基础;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author : linwen
 * @date : 下午7:24 2021/3/7
 */
public class 基础类型相等判断 {

    @Test
    public void test3(){
        int num = 10;
        //其他类型数据转换为String   String.valueOf()
        String s = String.valueOf(num);
        System.out.println(s);
        //string转为其他数据类型    Integer.parseInt()
        int num2 = Integer.parseInt(s);
        System.out.println(num2);
    }

    /**
     * intern返回常量池中的字符串对象地址值
     * 定义final的字符串也直接定义在字符串常量池中
     */
    @Test
    public void test1(){
        String s1 = "hello";
        String s2 = "world";
        String s3 = "helloworld";
        String s5 = "hello"+"world";
        String s4 = (s1+s2).intern();
        String s6 = s1+s2;
        final String s7 = "hello";
        String s8 = s7+"world";
        System.out.println(s3==s6);//有变量参与的定义，在堆空间中
        System.out.println(s3==s4);//intern返回常量池中的字符串对象地址值
        System.out.println(s3==s5);//相当于直接定义s5=helloworld
        System.out.println(s3==s8);//final定义的常量，相当于直接在常量池中定义的字符串

    }

    @Test
    public void test(){
        Collection collection = new ArrayList();
        collection.add(11);
        collection.add(22);
        ArrayList arrayList = new ArrayList();
        arrayList.add("33");
        arrayList.add(44);
        collection.addAll(arrayList);
        System.out.println(collection.size());
        System.out.println(collection);
        for (int i = 0; i < arrayList.size(); i++) {
            System.out.println(arrayList.get(i) instanceof Integer);
        }
        System.out.println();
    }
    @Test
    public void test2(){
        Integer i1;
        int i2 = 657;
        Integer i3 = Integer.valueOf(i2);
        Integer i4 = new Integer(i2);

        System.out.println(i2==i3);
        System.out.println(i3==i4);
        System.out.println(i4==i2);

    }

    public static void main(String[] args) {
        Object o = new Object(){
            public boolean equals(Object o){
                return true;
            }
        };
        System.out.println(o.equals("test"));
    }
}
